﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Wp.BLL;
using Wp.DAL;

public partial class Admin_Modules_Posts_Default : System.Web.UI.Page
{
    public static int PAGE_SIZE = 50;
    public int PageIndex { get; set; }
    public int TermTaxonomyId { get; set; }
    public string Title { get; set; }
    public static string Taxonomy = "category";
    protected void Page_Load(object sender, EventArgs e)
    {


        if (!IsPostBack)
        {
            LoadDDL();
            GetPropertyFromQueryString();
            LoadData();
        }
    }
    void GetPropertyFromQueryString()
    {
        PageIndex = CommonHelper.QueryStringInt("PageIndex", 1);
        TermTaxonomyId = CommonHelper.QueryStringInt("TermTaxonomyId", -1);
        Title = CommonHelper.QueryString("Title", "");
        ddlTermTaxonomy.SelectedValue = TermTaxonomyId.ToString();
        txtTitle.Text = Title;
    }
    void GetPropertyFromForm()
    {
        TermTaxonomyId = ddlTermTaxonomy.SelectedValue.ToInt();
        Title = txtTitle.Text;
    }
    void LoadDDL()
    {
        ddlTermTaxonomy.DataSource = TblTermTaxonomyManager.CreateInstant().SelectTblTermsTaxonomyGetChildFormat(null, Taxonomy); ;
        ddlTermTaxonomy.DataTextField = "Name";
        ddlTermTaxonomy.DataValueField = "Id";
        ddlTermTaxonomy.DataBind();
    }
    void LoadData()
    {
        int TotalRow = 0;
        List<TblPostsEntity> ls = TblPostsManager.CreateInstant().SelectTblPostByForAdmin("post", Title, TermTaxonomyId, "", Taxonomy, "CreatedDate", "DESC", PAGE_SIZE, PageIndex, out TotalRow);
        rpt.DataSource = ls;
        rpt.DataBind();
        smartPager1.PageSize = smartPager.PageSize = PAGE_SIZE;
        smartPager1.QueryStringKey = smartPager.QueryStringKey = "PageIndex";
        smartPager1.RowCount = smartPager.RowCount = TotalRow;
        smartPager1.NavigatePreviousText = smartPager.NavigatePreviousText = "<<";
        smartPager1.NavigateNextText = smartPager.NavigateNextText = ">>";
        //smartPager.Display=3;
        smartPager1.UrlFormatString = smartPager.UrlFormatString = string.Format("Default.aspx?TermTaxonomyId={0}&Title={1}", TermTaxonomyId, Title) + "&PageIndex={0}";
        smartPager1.Visible = smartPager.Visible = TotalRow > PAGE_SIZE;
    }
    protected void btnSeach_Click(object sender, EventArgs e)
    {
        GetPropertyFromForm();
        string Url = string.Format("Default.aspx?TermTaxonomyId={0}&Title={1}", TermTaxonomyId, Title) + "&PageIndex=1";

        Response.Redirect(Url);
    }
}